/* 导入所有定义好的的静态和动态路有权限 */
import {
  constantRoutes,
  asyncRoutes
} from '@/router'
console.log(constantRoutes, asyncRoutes, 333444)
// const menus=this.$store.getters.userInfo.roles.menus
// import store from '@/store'

// import router from '@/router'

export default {
  namespaced: true,
  state: {
    routes: [] // 帅选后的数据
  },
  mutations: {
    SET_ROUTES(state, menu) {
      state.routes = [...constantRoutes, ...menu]
    }
  },
  actions: {
    //  筛选
    filterRoute({
      commit
    }, menus) {
      /*
			1-获取所有的动态路由权限=====asyncRoutes【8个】 ：
		 【
				{
					path: '/approvals',
					component: Layout,
					name:''
					children: [{
						path: 'aa',
						name: 'approvals',
						component: () => import('@/views/approvals/index'),
						meta: {
							title: '审批',
							icon: 'tree-table'
						}
					}]
				},
			】
			2-获取当前用户所拥有的权限====menus：【  "employees" , "social_securitys" , "approvals" , "attendances" , "salarys" , "departments"】
			3-在所有的动态权限中去筛选用户所拥有的权限

			 */
      // console.log(menus, 9998877)
      const routes = []
      menus.forEach(item => {
        const route = asyncRoutes.filter(item2 => {
          return item2.name === item //  全部权限中每一项的name和当前的权限
          // return item2.children[0].name === item
        })
        routes.push(...route)
      })
      commit('SET_ROUTES', routes)
      return routes
      // //  将筛选出来的 routes 追加到  router中即可

      // router.addRoutes(routes)
    }
  }
}
